const app = getApp()
var api = require('../../../config/api.js');//接口api地址
var apiServer = require('../../../config/request.js');//接口api地址
Page({

  /**
   * 页面的初始数据
   */
  data: {
    itemnum: 253423231212,
    symptoms: "",
    name: "皮皮仓",
    age: 24,
    sex: "男",
    date: "2020-09-13 12:45",
    idcard: 422807188713872334,
    tel: 1213132424242,
    pathology: "头晕、咳嗽、浑身无力、要吃六味地黄丸才行！",
    result: "季节性感冒",
    price: 1000000,
    showDialog: false,
    selectstatus:"unckeck",
    selectid:"",
    showpatient:false,
    option:0,
    groups: [
      { text: '示例菜单', value: 1 },
      { text: '示例菜单', value: 2 },
      { text: '负向菜单', type: 'warn', value: 3 }
    ],
    showModalStatus: false,
    userType: 0,
    listsize:0,
    patientslist: [
      {
        id:1,
        name: "皮皮仓",
        sex: "女",
        data: "2020-09-16",
        itemno: 4242332314434446,
        phone: 1343498763524,
        symptomsnum: "首诊",
        checked: false
      },
      {
        id: 2,
        name: "李四",
        sex: "男",
        data: "2020-09-16",
        itemno: 3234224242425656,
        phone: 111398763524,
        symptomsnum: "复诊",
        checked: false
      },
      {
        id: 3,
        name: "老王",
        sex: "男",
        data: "2020-09-16",
        itemno: 2121334354675656,
        phone: 185942323233,
        symptomsnum: "首诊",
        checked: false
      },
      {
        id: 4,
        name: "张三",
        sex: "女",
        data: "2020-09-16",
        itemno: 2121334354634423,
        phone: 18598763524,
        symptomsnum: "复诊",
        checked: false
      },
      {
        id: 5,
        name: "张三",
        sex: "女",
        data: "2020-09-16",
        itemno: 2121334354634423,
        phone: 18598763524,
        symptomsnum: "首诊",
        checked: false
      },
      {
        id: 5,
        name: "张三",
        sex: "女",
        data: "2020-09-16",
        itemno: 2121334354634423,
        phone: 18598763524,
        symptomsnum: "复诊",
        checked: false
      }
    ]

  },
  onLoad:function(option){
   var that=this
   var id=wx.getStorageSync("usermsg").id;
   let data={
     "diagnosistype": "0",//首诊
     "creatorid": id
   }
    apiServer.Findpatientslist(data).then(res=>{
      if(res.data.code==0){
        that.setData({
          patientslist:res.data.data,
          listsize:res.data.data.length
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    this.setData({
      itemnum: app.globalData.itemno,
      symptoms: app.globalData.symptoms
    });
  },
 
  openDialog:function (e) {
    console.log(e)
    var currentStatu = e.currentTarget.dataset.statu;
    this.util(currentStatu)
  },
  util: function (currentStatu) {
    /* 动画部分 */
    // 第1步：创建动画实例 
    var animation = wx.createAnimation({
      duration: 200,  //动画时长
      timingFunction: "linear", //线性
      delay: 0  //0则不延迟
    });

    // 第2步：这个动画实例赋给当前的动画实例
    this.animation = animation;

    // 第3步：执行第一组动画：Y轴偏移240px后(盒子高度是240px)，停
    animation.translateY(240).step();

    // 第4步：导出动画对象赋给数据对象储存
    this.setData({
      animationData: animation.export()
    })

    // 第5步：设置定时器到指定时候后，执行第二组动画
    setTimeout(function () {
      // 执行第二组动画：Y轴不偏移，停
      animation.translateY(0).step()
      // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象
      this.setData({
        animationData: animation
      })

      //关闭抽屉
      if (currentStatu == "close") {
        this.setData(
          {
            showModalStatus: false
          }
        );
      }
    }.bind(this), 200)

    // 显示抽屉
    if (currentStatu == "open") {
      this.setData(
        {
          showModalStatus: true
        }
      );
    }
  },
  /**
  * 选择用户类型事件
  */
  selectUserType: function (e) {
    console.log(e)
    var that=this;
    let data1 = {
      "diagnosistype": "0",//首诊
      "creatorid": id
    }
    let data2 = {
      "diagnosistype": "1",//复诊
      "creatorid": id
    }
    that.setData({
      option: e.target.dataset.i
    })
    e.target.dataset.i && this.setData({
      userType: e.target.dataset.i
    });
    var id = wx.getStorageSync("usermsg").id
    console.log(that.data.option)
    if (that.data.option==0){
      apiServer.Findpatientslist(data1).then(res => {
        if (res.data.code == 0) {
          that.setData({
            patientslist: res.data.data,
            listsize: res.data.data.length
          })
        }
      })
    } else if (e.target.dataset.i ==1){
      apiServer.Findpatientslist(data2).then(res => {
        if (res.data.code == 0) {
          that.setData({
            patientslist: res.data.data,
            listsize: res.data.data.length
          })
          console.log("fu" + res.data.data.length)
        }
      })
     
    }
  },
  //复选框改变事件
  checkboxChange(e) {
    debugger
    console.log(e)
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)
    var ids = {};//选中的id
    const items = this.data.patientslist
    const values = e.detail.value

    for (var k = 0; k < values.length; k++) {
      var row = values[k].split(',');
      // ids = ids.concat(row [0])
    }
    console.log("ids"+ids )

    for (let i = 0, lenI = items.length; i < lenI; ++i) {
      items[i].checked = false

      for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
        if (items[i].id === values[j]) {
          items[i].checked = true
          break
        }
      }
    }
    this.setData({
      items
    })
  },


  //选中一个患者确定按钮
  selectonepatient:function(e){
    var that =this
    var currentStatu = e.currentTarget.dataset.statu;
    this.util(currentStatu)
    that.setData({
      showpatient:true
    })
  }
  
})